package cn.edu.hust.sse.software7.class3.servlet;

import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.edu.hust.sse.software7.class3.entities.EBCommonOnProduct;
import cn.edu.hust.sse.software7.class3.service.EBCommonOnProductService;
import cn.edu.hust.sse.software7.class3.serviceImpl.EBCommonOnProductServiceImpl;

public class CommonServlet extends HttpServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	EBCommonOnProductService ebcops = new EBCommonOnProductServiceImpl();
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String method = req.getParameter("method");
		if(method.equals("add")){
			HttpSession session = req.getSession();
			Long userId = (Long) session.getAttribute("userId");
			if(null == userId || userId <= 0){
				
			}else{
				String common = req.getParameter("common");
				String prodId = req.getParameter("prodId");
				Long pid = new Long(prodId);
				EBCommonOnProduct commonOnP = new EBCommonOnProduct(common, userId, pid, new Date());
				ebcops.addCommon(commonOnP);
				resp.sendRedirect("go?page=watchProdDetail&prod2Watch="+pid);
			}
		}
	}

}
